package shuiyuqing.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

import shuiyuqing.dto.DATA;
import shuiyuqing.network.GetHistoryHydInfo;
import shuiyuqing.network.GetRTHydInfo;

/**
 * 历史数据适配
 * Created by Administrator on 2016/3/22.
 */
public class HistoryDataAdapter extends BaseAdapter {

    List<GetHistoryHydInfo.RTData> datas = new ArrayList<GetHistoryHydInfo.RTData>();

    public void setDatas(List<GetHistoryHydInfo.RTData> datas) {
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(), R.layout.item_history_water,null);
            viewHolder.tv_dayRain = (TextView) convertView.findViewById(R.id.id_tv_riyuliang);
            viewHolder.tv_float = (TextView) convertView.findViewById(R.id.id_tv_liuliang);
            viewHolder.tv_kurong = (TextView) convertView.findViewById(R.id.id_tv_kurong);
            viewHolder.tv_shuiwei = (TextView) convertView.findViewById(R.id.id_tv_shuiwei);
            viewHolder.tv_votage = (TextView) convertView.findViewById(R.id.id_tv_votage);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.id_tv_time);
            viewHolder.tv_zongRain = (TextView) convertView.findViewById(R.id.id_tv_zongyuliang);
            viewHolder.v_flow = convertView.findViewById(R.id.id_v_flow);
            viewHolder.v_capacity = convertView.findViewById(R.id.id_v_capacity);

            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        GetHistoryHydInfo.RTData rtData = datas.get(position);
        Double kurong = rtData.getCAPACITY();
        if (kurong != null) {
            viewHolder.tv_kurong.setText(kurong + "");
        }
        else
        {
            viewHolder.tv_kurong.setText("无");
        }

        Double liuliang = rtData.getFLOW();
        if (liuliang != null) {
            viewHolder.tv_float.setText(liuliang + "");
        }
        else
        {
            viewHolder.tv_float.setText("无");
        }

        Double dayrain = rtData.getDAYRAINFALL();
        if (dayrain != null) {
            viewHolder.tv_dayRain.setText(dayrain + "");
        }
        else
        {
            viewHolder.tv_dayRain.setText("无");
        }

        Double waterLevel = rtData.getWATERLEVEL();
        if (waterLevel != null) {
            viewHolder.tv_shuiwei.setText(waterLevel + "");
        }
        else
        {
            viewHolder.tv_shuiwei.setText("无");
        }

        String time = rtData.getSURVEYTIME();
        viewHolder.tv_time.setText(time);

        Double votage = rtData.getVOLTAGE();
        if (votage != null)
        {
            viewHolder.tv_votage.setText(votage+"");
        }
        else
        {
            viewHolder.tv_votage.setText("无");
        }

        Double zongRain = rtData.getSUMRAINFALL();
        if (zongRain != null)
        {
            viewHolder.tv_zongRain.setText(zongRain+"");
        }
        else
        {
            viewHolder.tv_zongRain.setText("无");
        }

        if (rtData.getSTID() == 58.0)
        {
            viewHolder.v_flow.setVisibility(View.VISIBLE);
        }
        else
        {
            viewHolder.v_flow.setVisibility(View.GONE);
        }

        if (rtData.getSTID() == 60.0)
        {
            viewHolder.v_capacity.setVisibility(View.VISIBLE);
        }
        else
        {
            viewHolder.v_capacity.setVisibility(View.GONE);
        }

        return convertView;
    }

    public static class ViewHolder
    {
        public TextView tv_time;
        public TextView tv_kurong;
        public TextView tv_shuiwei;
        public TextView tv_float;
        public TextView tv_dayRain;
        public TextView tv_zongRain;
        public TextView tv_votage;

        public View v_flow;
        public View v_capacity;
    }


}
